package com.yiwenup.leetcode.offer;

import com.yiwenup.leetcode.TreeNode;

/**
 * https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
 * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
 * 内存消耗：38.2 MB, 在所有 Java 提交中击败了72.47%的用户
 **/
public class No054 {
    private int k, res;

    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        helper(root);
        return res;
    }

    public void helper(TreeNode node) {
        if (node == null) return;
        helper(node.right);
        if (--k == 0) res = node.val;
        helper(node.left);
    }
}
